﻿// ===============================================================================
// DotNet.Platform 开发框架 2016 版权所有
// ===============================================================================

using System.Text;
using DotNet.Encrypt;

namespace DotNet.EduWebApi
{
    public class EncryptUtil
    {
        /// <summary>
        /// 解密字符串
        /// </summary>
        /// <param name="decryptString">待解密的字符串</param>
        /// <param name="name">参数名称</param>
        /// <returns>返回原文</returns>
        public static DecryptBoolMessage Decrypt(string decryptString, string name = null)
        {
            string title = name ?? "字符串";
            if (string.IsNullOrEmpty(decryptString))
            {
                return new DecryptBoolMessage
                {
                    Success = false,
                    Message = "请指定"+ title
                };
            }
            try
            {
                var p = StringEncrypt.Decrypt(decryptString);
                var result = new DecryptBoolMessage
                {
                    Success = true,
                    Data = p
                };
                return result;
            }
            catch
            {
                return new DecryptBoolMessage
                {
                    Success = false,
                    Message = "无效的"+ title
                };
            }
        }
    }
}